package com.sugon.controller.device;

import com.alibaba.fastjson.JSON;
import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevAlarmEntity;
import com.sugon.service.DevAlarmService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 设备报警码信息表Controller
 *
 * @author YuXD
 * @date 2020-05-17 13:41:21
 */
@Controller
@RequestMapping("devalarm")
public class DevAlarmController {
    @Autowired
    private DevAlarmService devAlarmService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevAlarmEntity> devAlarmList = devAlarmService.queryList(query);
        int total = devAlarmService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devAlarmList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody DevAlarmEntity devAlarm) {
        devAlarmService.save(devAlarm);
        return R.ok();
    }

    /**
     * 修改
     */
    @AutoLog("设备报警码信息表--修改")
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody DevAlarmEntity devAlarm) {
        devAlarmService.update(devAlarm);

        return R.ok();
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevAlarmEntity devAlarm = devAlarmService.queryObject(id);

        return R.ok().put("devAlarm", devAlarm);
    }

    /**
     * 删除
     */
    @AutoLog("设备报警码信息表--删除")
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devAlarmService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevAlarmEntity> list = devAlarmService.queryList(params);

        return R.ok().put("list", list);
    }

    @RequestMapping("/imports")
    @ResponseBody
    public R imports(@RequestParam("file") MultipartFile file) throws Exception {

        devAlarmService.imports(file);

        return R.ok();
    }
}
